package com.pw.gmall.realtime.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pw.gmall.realtime.entities.ProductStats;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Clock;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @Author: linux_future
 * @since: 2022/3/18
 **/
public class TestCollect {
    public static void main(String[] args) throws ParseException {
        testIkAnalyzer();
        String kw="";
        AtguiguUtils.splitByIkAnalyze(kw);

    }

    private static void testIkAnalyzer() {
        String ky="我是中国人";
        IKSegmenter seg = new IKSegmenter(new StringReader(ky), true);
        ArrayList<String> words = new ArrayList<>();
        try {
            Lexeme next = seg.next();
            while (next != null) {
                String word = next.getLexemeText();
                words.add(word);
                next = seg.next();
            }

            System.out.println(words.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void testDateToTs() throws ParseException {
        String time = "2021-03-23 20:09:23";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDate localDate = LocalDate.parse(time, formatter);
        LocalDateTime tim = LocalDateTime.parse(time, formatter);

        Instant instant = Clock.systemUTC().instant();
        long s = instant.getEpochSecond();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = format.parse(time);
        System.out.println(parse.getTime());

        System.out.println(instant);
        System.out.println(tim);
        System.out.println(localDate);

        AtguiguUtils.dateTimeToTs(time);
    }

    private static void DateTimeToTs(String time) {
    }

    private static void filedTest() {
        Class<ProductStats> vs = ProductStats.class;
        Field[] fields = vs.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field.getName());
        }
        String names = AtguiguUtils.fieldsTOString(fields);
        String[] len = names.split(",");
        System.out.println(len.length);
        System.out.println(names);

    }

    private static void tes1() {
        String str = "{\n" +
                "    \"delivery_address\": \"第7大街第2号楼7单元678门\",\n" +
                "    \"order_comment\": \"描述715264\",\n" +
                "    \"original_total_amount\": 8376.00,\n" +
                "    \"order_status\": \"1005\",\n" +
                "    \"consignee_tel\": \"13475141081\",\n" +
                "    \"trade_body\": \"华为 HUAWEI P40 麒麟990 5G SoC芯片 5000万超感知徕卡三摄 30倍数字变焦 6GB+128GB亮黑色全网通5G手机等2件商品\",\n" +
                "    \"id\": 26449,\n" +
                "    \"operate_time\": \"2022-03-18 10:14:36\",\n" +
                "    \"consignee\": \"谢岩中\",\n" +
                "    \"create_time\": \"2022-03-18 10:14:36\",\n" +
                "    \"expire_time\": \"2022-03-18 10:29:36\",\n" +
                "    \"coupon_reduce_amount\": 0.00,\n" +
                "    \"out_trade_no\": \"875154948844718\",\n" +
                "    \"total_amount\": 8387.00,\n" +
                "    \"user_id\": 14,\n" +
                "    \"img_url\": \"http://img.gmall.com/675353.jpg\",\n" +
                "    \"province_id\": 12,\n" +
                "    \"feight_fee\": 11.00,\n" +
                "    \"activity_reduce_amount\": 0.00\n" +
                "}";
        JSONObject data = JSON.parseObject(str);
        String str2 = "id,consignee,consignee_tel,total_amount,order_status,user_id,payment_way,delivery_address,order_comment,out_trade_no,trade_body,create_time,operate_time,expire_time,process_status,tracking_no,parent_order_id,img_url,province_id,activity_reduce_amount,coupon_reduce_amount,original_total_amount,feight_fee,feight_fee_reduce,refundable_time";
        List<String> columns = Arrays.asList(str2.split(","));
        System.out.println(columns);
        // data.keySet().removeIf(key -> !columns.contains(key));
        Set<String> keys = data.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next();
            if (columns.contains(key)) {
                System.out.println(key);
            } else {
                System.out.println("===============");
            }
            System.out.println();
        }
        System.out.println(columns);

    }

}
